<?php
namespace controller;
use exceptions\InputValidationException;
use model\IndexQuery;
class InputValidator{
	
	public static function validateEmail($email){
		 if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
		 	throw new InputValidationException(InputValidationException::EMAIL_INVALID);
		 }
		 
	}
	
	public static function isEmailAvailable($email){
		if(IndexQuery::emailExists($email)){
			throw new InputValidationException('Email already exists');
		}
	}
	
	public static function isUserNameAvailable($username){
		if(IndexQuery::usernameExists($username)){
			throw new InputValidationException('Username already exists');
		}
	}
	
	public static function validatePassword($password){
		if(strlen($password) < 8){
			throw new InputValidationException(InputValidationException::PASSWORD_SHORT);
		}
		
		if(strlen($password) > 60){
			throw new InputValidationException(InputValidationException::PASSWORD_LONG);
		}
		
	}
	
	public static function checkRepeatPassword($password,$repeatPassword){
		if($password != $repeatPassword){
			throw new InputValidationException(InputValidationException::PASSWORD_MISMATCH);
		}
		
	}
}